package com.shop.service.impl;

import com.github.pagehelper.PageInfo;
import com.shop.entity.ProductImage;
import com.shop.mapper.ProductImageMapper;
import com.shop.service.ProductImageService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("productImageService")
@RequiredArgsConstructor
@Transactional(rollbackFor = RuntimeException.class,
        propagation = Propagation.REQUIRED)
public class ProductImageServiceImpl implements ProductImageService {
    private final ProductImageMapper productImageMapper;
    @Override
    public PageInfo<ProductImage> listProductImage(int pageNum, int pageSize) {
        return productImageMapper.listProductImage(pageNum, pageSize);
    }

    @Override
    public PageInfo<ProductImage> listWithProductImage(int pageNum, int pageSize) {
        return productImageMapper.listWithProductImage(pageNum, pageSize);
    }

    @Override
    public List<ProductImage> getProductImageById(Integer id) {
        return productImageMapper.getProductImageById(id);
    }

    @Override
    public void addProductImage(ProductImage productImage) {
        productImageMapper.addProductImage(productImage);
    }

    @Override
    public void deleteProductImage(Integer id) {
        productImageMapper.deleteProductImage(id);
    }

    @Override
    public void updateProductImage(Integer id, String imageUrl, Integer isMain) {
        productImageMapper.updateProductImage(id, imageUrl, isMain);
    }

    @Override
    public int getTotal() {
        return productImageMapper.getTotal();
    }
}
